home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / stack_language / stack-language.c < prev   
Encoding:
Text File  |  1994-06-06  |  9.3 KB  |  361 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 17 Nov 1992
  4. **
  5. **  File  : Stack-Language.c
  6. **
  7. **  (c) by VIONA-Development 1992/93
  8. **
  9. **
  10. **  HOW TO USE THE INTUIGFX STACK-LANGUAGE
  11. **
  12. **
  13. **  This is an expamle for IntuiGfx.
  14. **  The IntuiGfx.h includes a stack language.
  15. **  This language is used for drawing, building gadgets,
  16. **  menus a.s.o.
  17. **
  18. **  You can use (call/run) the stack-language in serveral ways.
  19. **
  20. **  1. In structures as little programs
  21. **  2. With the interpeter "EI_Interpret" a.s.o.
  22. **
  23. **  The stack language has many functions and commands
  24. **  (see IntuiGfx.h and IntuiGfx.doc).
  25. **
  26. **  Please read the IntuiGfx.doc to understand how
  27. **  the stack-language works and see the following paragraph.
  28. **
  29. **  To help you to use the language for your own application
  30. **  we want to build an example.
  31. **
  32. **  We build a BoolGagdet with a triangle in it.
  33. **  At first you should know how to open a EGS-Window, because
  34. **  we need a window to display the gadget.
  35. **
  36. **  If you have a window structure, you should give
  37. **  the address of the BoolGadget to the window
  38. **  before you open it. Like:
  39. **
  40. **       newwin.gadgets=&myBoolGadget;
  41. **
  42. **  At first we make a normale triangle.
  43. **  For this work we need the following commands:
  44. **
  45. **  IG_CDark    = Get the dark color and put it on the stack
  46. **  IG_Color    = Set color dark (first stack parameter)
  47. **
  48. **  IG_GETFI+0  = Get the 0. frame parameter and put it on the stack
  49. **  IG_GETFI+1  = Get the 1. frame parameter and put it on the stack
  50. **
  51. **  IG_Const+2  = Put 2 on the stack
  52. **  IG_IDIV     = Divide parameter[stack-1] / para[stack-0]
  53. **                Like:  IG_GETFI+0,IG_Const+2,IG_IDIV,
  54. **                           X     ,     2      ,   /   (like HP)
  55. **  IG_Move     = Move the cursor to the pos. stack-1,stack-0
  56. **  IG_Draw     = Draws a line from the current pos. the
  57. **                pos. stack-1,-stack-0
  58. **
  59. **  IG_NEG      = Negation from the stack parameter - 0
  60. **
  61. **  IG_RTF+2    = Remove 2 frameparamter and returns to the caller
  62. **
  63. **
  64. **  Here comes the routine:
  65. **
  66. **
  67. ** IntuiGfx:
  68. **
  69. ** "Triangle" draws a triangle in a frame given by
  70. ** width an height. In the following description
  71. ** is shown how the routine draws the triangle.
  72. ** To understand it, please think like a plotter
  73. ** and take the positions as relative coordinates.
  74. **
  75. ** Triangle positions are:
  76. **
  77. ** POS       X            Y
  78. **
  79. ** 1   =  width/2  ,  height/2     | Move to the position
  80. **
  81. ** 2   = -width/2  ,  height/2     | Draw to the position
  82. **
  83. ** 3   =  width    ,     0         | Draw
  84. **
  85. ** 4   = -width/2  , -height/2     | Draw
  86. **
  87. **
  88. **        0                    Location
  89. **       0############         ------> + x
  90. **        |   BOX    |         |
  91. **      / |    1,4   |         |
  92. **    h   |    /\    |         |
  93. **      \ |   /  \   |         |
  94. **        | 2------3 |--      \/
  95. **        |    dx    |dx      + y
  96. **        ############--
  97. **        |dx|    |dx|
  98. **                         **  dx is use in the second part !
  99. **          \   /
  100. **            w
  101. **
  102. ** STACK for Input:
  103. **                   +1 = width
  104. **                   +0 = height
  105. **
  106. */
  107.  
  108. ULONG triangle  [] = {
  109. /* NO.*/
  110. /* 1  */ IG_CTxtFront,IG_Color,          /* Set Color              */
  111. /* 2  */ IG_GETFI+1,IG_Const+2,IG_IDIV,  /* width / 2  = x         */
  112. /* 3  */ IG_GETFI+0,IG_Const+2,IG_IDIV,  /* height/ 2  = y         */
  113. /* 4  */ IG_Move,                        /* move to Pos x,y        */
  114.  
  115. /* 5  */ IG_GETFI+1,IG_Const+2,
  116. /* 6  */ IG_IDIV,IG_NEG,                 /* (width / 2)*(-1)  = x  */
  117. /* 7  */ IG_GETFI+0,IG_Const+2,IG_IDIV,  /* (height/ 2)       = y  */
  118. /* 8  */ IG_Draw,
  119.  
  120.      IG_GETFI+1,IG_Const+0,IG_Draw,  /* x= width, y = 0        */
  121.  
  122.      IG_GETFI+1,IG_Const+2,
  123.      IG_IDIV,IG_NEG,
  124.                                                  /* (width / 2)*(-1)  = x  */
  125.      IG_GETFI+0,IG_Const+2,
  126.      IG_IDIV,IG_NEG,
  127.                                               /* (height/ 2)*(-1)  = y  */
  128.      IG_Draw,
  129.  
  130. /*
  131. **  for using only this routine in gadget structure please replace
  132. **
  133. **        IG_RTF+2 with IG_RTS
  134. */
  135.  
  136.      IG_RTF+2                         /* Remove parameter,      */
  137. };                                 /* and returns            */
  138.  
  139. /*
  140. ** To test the routine please change the line in the
  141. ** gadget structure at the end of the text and compile it.
  142. **
  143. **      (IG_IntuiGfxPtr) &triangle,      * active          *
  144. **
  145. ** Please play with the routine and his parameter.
  146. ** For example:
  147. **             Change the height to bring the triangle
  148. **             in the top of the gadget
  149. ** see line 3
  150. **             IG_GETFI+0,IG_Const+20,IG_IDIV,
  151. **                                 ^^
  152. ** a.s.o. ....
  153. **
  154. **
  155. ** 2. The next step is
  156. **
  157. ** We want that the triangle routine uses a specified
  158. ** distance from the gadget border.
  159. **
  160. ** For this work we need the parameter dx (see upper).
  161. ** dx tells us the distance from the triangle to the bottom and
  162. ** border of the gadget.
  163. **
  164. ** Commands are used:
  165. **
  166. ** IG_Locate00 = locate to 0,0
  167. **
  168. ** IG_Locate   = locate to x,y [stack-1,stack-0]
  169. **
  170. ** IG_JSR      = jump to the sub routine on the parameter stack-0
  171. **
  172. **
  173. **
  174. ** The algorithm is:
  175. **
  176. ** We locate the cursor to a new position (dx/2,dx/2).
  177. **                                          x  , y
  178. ** then we substitude dx from the width,height
  179. ** and call the triangle routine.
  180. **
  181. ** call triangle to draw.
  182. **
  183. ** see below:
  184. **
  185. */
  186.  
  187. /*
  188. **
  189. ** IntuiGfx
  190. **
  191. ** Prepaed the parameter for triangle.
  192. ** Set the locations for the zero point.
  193. ** And subs the offset from the frame (width,height).
  194. **
  195. ** This give us the posibilities of scalable gadgets.
  196. **
  197. **
  198. ** STACK:
  199. **       0 = height
  200. **       1 = width
  201. **       2 = dx
  202. **
  203. **/
  204.  
  205. ULONG sc_triangle [] = {
  206.              IG_GETFI+2,IG_Const+2,IG_IDIV,
  207.              IG_GETFI+2,IG_Const+2,IG_IDIV,
  208.              IG_Locate,
  209.              IG_GETFI+1,IG_GETFI+2,IG_SUB,
  210.              IG_GETFI+0,IG_GETFI+2,IG_SUB,
  211.              (ULONG)&triangle,IG_JSR,IG_Locate00,
  212.              IG_RTF+3};
  213. /*
  214. **
  215. ** But at first we must build a calling routine
  216. ** with the parameter dx.
  217. **
  218. ** The algo.
  219. **
  220. ** 1. Locate to 0,0
  221. **
  222. ** 2. Put the offset on the stack
  223. **    (dx must mod 2, because we divide the int by 2)
  224. **
  225. ** 3. put width on the stack
  226. **
  227. ** 4. put height on the stack
  228. **
  229. ** 5. call sc_triangle
  230. **
  231. ** Here comes the routine for the algo.
  232. **
  233. */
  234.  
  235. /*
  236. ** IntuiGfx - routine for marking selected menu item
  237. **      1     0
  238. ** ( width, height)
  239. */
  240.  
  241. ULONG myGFX         [] ={
  242.              IG_Locate00,
  243.              IG_Const+64,   /* Offset from the border */
  244.              IG_GETFI+1,
  245.              IG_GETFI+0,
  246.              (ULONG)&sc_triangle,IG_JSR,
  247.              IG_RTS};
  248.  
  249.  
  250. /*
  251. ** --------------------------------------------------------------
  252. **
  253. ** To test the routine please change the line in the
  254. ** gadget structure at the end of the text and compile it.
  255. **
  256. **           (IG_IntuiGfxPtr) &myGFX,        * active          *
  257. **
  258. ** Make changes with the offset and see what happens.
  259. **
  260. **
  261. ** 3.
  262. **
  263. ** The thrid step is to make a scaleable Gadget.
  264. ** That means a gadget is automatical resizing
  265. ** its image, if you size the window, for example.
  266. **
  267. ** For doing this work append the following lines to
  268. ** the event handling from the window.
  269. **
  270.       case EI_iSizeVerify:
  271.  
  272.             printf("VerifySizing ! \n");
  273.  
  274.             EI_RemoveGadget(Window,(struct EI_Gadget *)&myBoolGadget);
  275.  
  276.             ReplyMsg ( (struct Message *)imess );
  277.             break;
  278.  
  279.       case EI_iWindowSize:
  280.  
  281.             printf("Sizing ! \n");
  282.  
  283.             EI_LockIntuition();
  284.  
  285.             myBoolGadget.class.width  = Window->width-
  286.             myBoolGadget.class.leftEdge*2;
  287.             myBoolGadget.class.height = Window->height-
  288.             myBoolGadget.class.topEdge*2;
  289.                           * *2 for the border *
  290.  
  291.             EI_AddGadget(Window,(struct EI_Gadget *)&myBoolGadget);
  292.  
  293.             EI_UnlockIntuition();
  294.  
  295.             ReplyMsg((struct Message *)imess);
  296.             break;
  297.  
  298. **
  299. ** It is very easy, if the windowing is sizing (see VerifySizing)
  300. ** we remove the BoolGadget and get a clean window.
  301. **
  302. ** We wait for sizing finish. Then we LockEGSIntui so that nothing
  303. ** can happens.
  304. **
  305. ** After this we get from the window structure the new window size
  306. ** and put it in the BootGadget structure.
  307. **
  308. ** Then we add the gadget to the window and UnlockEGSIntui.
  309. **
  310. ** This is one way to make resizeable gadgets a other but the
  311. ** same base is to use the egsgadbox.library functions.
  312. ** (see egsgadbox.doc)
  313. **
  314. */
  315.  
  316. /************************** TEST GADGET *************************/
  317.  
  318. struct EI_BoolGadget myBoolGadget = {
  319.  
  320. /*  Gadget structure */
  321.  
  322.       {
  323.        NULL,NULL,                      /* prev,next        */
  324.        0,0,                            /* checkTop,leftEdge*/
  325.        10,10,                          /* leftEdge,topEdge */
  326.        WIN_WIDTH -20,
  327.        WIN_HEIGHT-20,
  328.                        /* width , height   */
  329.        0x111,                          /* id               */
  330.  
  331. /*
  332.        (IG_IntuiGfxPtr) &triangle,
  333. */
  334.        (IG_IntuiGfxPtr) &myGFX,        /* active           */
  335.        NULL,                           /* pasive           */
  336.        NULL,                           /* select           */
  337.        NULL,                           /* release          */
  338.  
  339.     EI_STD_COMPLEMENT |                 /* flags           */
  340.     EI_STD_HIGHLIGHT |
  341.     EI_REL_VERIFY     |
  342.     EI_TOGGLE_SELECT  ,
  343.  
  344.        EI_BOOL_GADGET,                  /* Type            */
  345.        'A',                            /* hotkey          */
  346.        NULL,                           /* Call            */
  347.        NULL                            /* Userdata        */
  348.       },
  349.  
  350.     1,                                  /* flags=True       */
  351.                         /* (use the Gadgetflags */
  352.     0,0,0,                              /* 3 pads           */
  353.     NULL,                               /* EI_GadgetArrayPtr*/
  354.     NULL                                /* exclude,include  */
  355.       };
  356. /*
  357. */
  358.  
  359.  
  360.  
  361.